package com.zzw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzw.pojo.User;
import com.zzw.mapper.UserMapper;
import com.zzw.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户ServiceImpl
 *
 * @Author: zhangzhiwei
 * @Date: 2022/4/6 23:36
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public int register(User user) {
        return userMapper.insert(user);
    }

    @Override
    public boolean isRegister(String email) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", email);
        return userMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public String login(String email, String password) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", email);
        queryWrapper.eq("password", password);
        User user = userMapper.selectOne(queryWrapper);
        if(null == user){
           return null;
        } else {
            return email;
        }
    }
}
